<?php
   
class API_Auth extends API_Class {
    
    protected static $sess;
    
    public function static_init(){
        self::$sess = Zend_Registry::get("sess");
    }

    public function doAuth($acc, $pass = ""){
        $cl = API_Clients::getClientByAcc($acc);
        if(!$cl)return false;
        
        // @todo password =)
        
        self::$sess->acc = $acc;
        self::$sess->client = $cl;
        
        return true;
    }
    
    public function reCache(){
        if(!self::isAuth())
            return false;
        $cl = API_Clients::getClientByAcc(self::$sess->acc);
        if(!$cl)
            return false;
        self::$sess->client = $cl;
        return true;        
    }
    
    public function doExit(){
        self::$sess->acc = "";
        self::$sess->client = array();        
    }
    
    public function getMyData(){
        if(!self::isAuth())
            return array();
        return self::$sess->client;
    }
    
    public function isAuth(){
        if(!isset(self::$sess->acc) || !isset(self::$sess->client) || !self::$sess->acc || !self::$sess->client)
            return false;
        
        // ...    
        
        return true;
    }
    
}